package com.okaixz.client.service.impl;

import com.okaixz.client.model.domain.Huashu;
import com.okaixz.client.mapper.HuashuMapper;
import com.okaixz.client.service.IHuashuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.okaixz.common.constant.CommonConstants;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cdz
 * @since 2025-11-05
 */
@Service
public class HuashuServiceImpl extends ServiceImpl<HuashuMapper, Huashu> implements IHuashuService {

    @Override
    public String getHuaShu(String ask, String outStyle, Integer sex) {
        if (ask == null) {
            return null;
        }
        if (sex == null) {
            return null;
        }
        if (outStyle == null) {
            return null;
        }
        boolean filter = filter(ask);
        if (!filter) {
            return null;
        }

        List<Huashu> list = lambdaQuery()
                .eq(Huashu::getAsk, ask)
                .eq(Huashu::getOutStyle, outStyle)
                .eq(Huashu::getStatus, CommonConstants.STATUS_ENABLE)
                .in(Huashu::getSex, sex, 0)
                .list();
        if (list == null||list.size()==0) {
            return null;
        }
        //生成随机数 最大为list.size() 最小0
        int random = (int) (Math.random() * list.size());
        Huashu huashu = list.get(random);
        return huashu.getAnswer();
    }

    public boolean filter(String ask) {
        if (ask == null) {
            return false;
        }
        if (ask.equals("在干嘛")||ask.equals("在干什么")||ask.equals("干嘛呢")||ask.equals("我去洗澡了")||ask.equals("我先去洗澡了")||ask.equals("我去洗澡先")) {
            return true;
        }
        return false;
    }
}
